//https://leetcode.cn/problems/longest-substring-without-repeating-characters/submissions/562832142/
class Solution {
public:
    int lengthOfLongestSubstring(const string& s) {
        unordered_map<char, int> charMap;
        int start = 0, maxLength = 0;

        for (int i = 0; i < s.size(); ++i) {
            if (charMap.find(s[i]) != charMap.end() && charMap[s[i]] >= start) {
                start = charMap[s[i]] + 1;
            }
            charMap[s[i]] = i;
            maxLength = max(maxLength, i - start + 1);
        }

        return maxLength;
    }
};
